//
//  Label.swift
//  MGS_Example
//
//  Created by Mac on 2022/3/2.
//  Copyright © 2022 CocoaPods. All rights reserved.
//

import Foundation
import UIKit

final public class Label: UILabel {
  /// set textInsets
  public var textInsets: UIEdgeInsets = .zero
  
  public override func drawText(in rect: CGRect) {
    super.drawText(in: rect.inset(by: textInsets))
  }
  
  public override func textRect(forBounds bounds: CGRect, limitedToNumberOfLines numberOfLines: Int) -> CGRect {
    let insets = textInsets
    var rect = super.textRect(forBounds: bounds.inset(by: insets),
                              limitedToNumberOfLines: numberOfLines)
    
    rect.origin.x -= insets.left
    rect.origin.y -= insets.top
    rect.size.width += (insets.left + insets.right)
    rect.size.height += (insets.top + insets.bottom)
    return rect
  }
}
